package com.ksd.pug.clound.service;

import com.ksd.pug.clound.pojo.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author 飞哥
 * @Title: 学相伴出品
 * @Description: 飞哥B站地址：https://space.bilibili.com/490711252
 * 记得关注和三连哦！
 * @Description: 我们有一个学习网站：https://www.kuangstudy.com
 * @date 2022/3/3$ 23:32$
 */
@Service
@CacheConfig(cacheNames = "com.ksd.pug:user")
@Slf4j
public class UserRemoteService {

    @Autowired
    private RestTemplate restTemplate;


    @Cacheable(key = "'getUser:'+#id")
    public SysUser findUser(Long id) {
        log.info("------------get------------------");
        String url = "http://pug-hystrix-user-service/user/" + id;
        return restTemplate.getForObject(url, SysUser.class);//
    }

    @CacheEvict(key = "'getUser:'+#id")
    public void delUser(Long id) {
        log.info("------------del------------------");
    }

}
